unit UnitCadConvenios;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UnitCadModelo, StdCtrls, DBCtrls, ComCtrls, Mask,
  ExtCtrls, Buttons, Grids, DBGrids, SMDBGrid, jpeg, db;

type
  TFormCadConvenio = class(TFormCadModelo)
    Label1: TLabel;
    DBEdit1: TDBEdit;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    DBCheckBox3: TDBCheckBox;
    TabSheet4: TTabSheet;
    SMDBGrid4: TSMDBGrid;
    DBLookupComboBox1: TDBLookupComboBox;
    Label3: TLabel;
    Label4: TLabel;
    DBLookupComboBox2: TDBLookupComboBox;
    TabSheet1: TTabSheet;
    SMDBGrid1: TSMDBGrid;
    DBEdit3: TDBEdit;
    Label5: TLabel;
    Label6: TLabel;
    DBEdit4: TDBEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btOKClick(Sender: TObject);
    procedure btCancelarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormCadConvenio: TFormCadConvenio;

implementation

uses UnitConvenios, UnitPrincipal;

{$R *.dfm}

procedure TFormCadConvenio.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  FormCadConvenio := nil;
end;

procedure TFormCadConvenio.btOKClick(Sender: TObject);
begin
  inherited;
  try
    if FormConvenios.qryDados.State in [dsInsert,dsEdit] then
      FormConvenios.qryDados.Post;
    if FormConvenios.qryHistorico.State in [dsInsert,dsEdit] then
      FormConvenios.qryHistorico.Post;
    if FormConvenios.qryFaixas.State in [dsInsert,dsEdit] then
      FormConvenios.qryFaixas.Post;
    ModalResult := mrOk;
  except
    on E: Exception do
    begin
      FormPrincipal.TrataErro(E);
      ModalResult := mrNone;
    end;
  end;
end;

procedure TFormCadConvenio.btCancelarClick(Sender: TObject);
begin
  inherited;
  if FormConvenios.qryDados.State in [dsInsert,dsEdit] then
     FormConvenios.qryDados.Cancel;
  if FormConvenios.qryHistorico.State in [dsInsert,dsEdit] then
     FormConvenios.qryHistorico.Cancel;
  if FormConvenios.qryFaixas.State in [dsInsert,dsEdit] then
     FormConvenios.qryFaixas.Cancel;
end;

end.
